Elements		= {

	button		: function( args, callback) {
	
		args.class = 'Button' + (( args.class )? " " + args.class : "" ) 
		el = Engine.element( 'a', { 'target': '_blank' } );
		el.innerHTML =  args.value
		delete 			args.value
		
		for( key in args ) el.setAttribute( key, args[key] );
		
		//else if( callback ) {
		if( callback ) {
			el.callback = callback;
			el.trigger = Elements.button_proto_trigger; 
			el.addEventListener( 'click', el.trigger );
		}
		
		return el;	
	},
	
	button_proto_trigger	: function() {
	
		Engine.triggerlist.view(
			this.callback.type,
			this.callback.column? this.callback.column : Engine.findColumn( this ),
			this.callback
		);
	
	},

	text		: function( args, callback) {
	
		el = Engine.element( 'span', { 'class': 'Text' });
		el.innerHTML = args.value;
		
		return el;	
	},
	
	input		: function( args, callback) {
	
		el = Engine.element( 'input', { 'class': 'Input' });
		
		for( key in args ) el.setAttribute( key, args[key] );
		
		if( callback ) {
			el.callback = callback;
			el.addEventListener( 'change', Elements.input_proto_trigger );
		}
		
		return el;	
	},
	
	input_proto_trigger	: function() {
		
		this.callback.value = this.value;
		
		Engine.triggerlist.json( this.callback.type, this.callback.action, this.callback );
	
	},
	
	textarea		: function( args, callback) {
	
		el = Engine.element( 'textarea', { 'class': 'Input' });
		el.args = args;
		
		for( key in args ) el.setAttribute( key, args[key] );
		
		el.addEventListener( 'focus', function(){
			this.className += ' focus';
			this.wordcount.className += ' focus';
		});
		
		if( callback.action == 'wordcount' )
			Elements.textarea_wordcount(el, callback );
		
		return el;	
	},
	
	textarea_wordcount	: function( el, callback ) {
	
		el.post_append 	= function() {
		
			wordcount	= Engine.element( 'div', { 'class': 'textarea_wordcount' });
			count		= Engine.element( 'span' );
			button		= Engine.element( 'input', { 'type': 'button', 'value': 'Tweet' });
		
			this.parentNode.appendChild( wordcount );
			wordcount.appendChild( count );
			wordcount.appendChild( button );
			
			this.addEventListener( 'keyup', Elements.textarea_wordcount_listener );
			button.addEventListener( 'click', Elements.textarea_button_listener );
			
			button.callback = callback;
			button.parent = this;
			count.innerHTML = wordcount.max = callback.count;
			this.wordcount = wordcount;
		
		}
	},
	
	textarea_wordcount_listener	: function( evt ) {
		
		var total = this.wordcount.max - this.value.length;
		if( total < 0 ) {
			this.value = this.value.substr( 0, this.wordcount.max );
			total = 0;
		}
		
		this.wordcount.firstChild.innerHTML = total
	},
	
	textarea_button_listener	: function( evt ) {
		
		this.callback.value = this.parent.value;
		Engine.triggerlist.json( this.callback.type, this.callback.action, this.callback );
	},

	
	ulist		: function( args, callback) {
		
		// Create ul element
		el = Engine.element( 'ul', { 'class': args.class });
		el.args = args;

		
		// Populate num listed ul elements
		if( args.values[0] ) {
			args.values.reverse().forEach( Elements.ulist_add_line, el );
			
			// Calculate height
			if( args.height )
				el.post_append = Elements.ulist_post_append_height;
		
		// Populate action listed ul elements
		} else if( args.values )
				el.post_append = Elements.ulist_post_append_list;
		
		//create floating options
		//create update options
		
					
		
		if( callback ) {
			el.callback = callback;
			//el.addEventListener( 'change', Elements.input_proto_trigger );
		}
		
		return el;	
	},
	
	ulist_add_line : function( li ) {
		
		line = '';
		for( key in li ) line += "<span class='" + key + "'>" + li[key] + "</span>"; 
		this.innerHTML = "<li>" + line + "</li>" + this.innerHTML;

	},
	
	ulist_post_append_height	: function() {
				
		var height = 0;
			
		for( n=0; n<= this.args.height; n++ )
			if( this.children[n] )
				height += this.children[n].offsetHeight;
				
		this.style.height = height + 'px';
	},
	
	ulist_post_append_list		: function() {
	
		for( action in this.args.values ) {
				
			li = Engine.element( 'li', { 'id': action });
			li.innerHTML = this.args.values[ action ];
			
			this.appendChild( li );
			Engine.trigger( li, 'click' )
		}
	},
	
	ulist_proto_trigger	: function() {
		
		this.callback.value = this.value;
		
		Engine.triggerlist.json( this.callback.type, this.callback.action, this.callback );
	
	},

}
/*
/////// TEXTFIELD OBJECT (auto-update)
var Textfield = function( vars, bare ) {
	
	obj = ( bare )? new Element( "div", { class:"container" }).update( vars.descr ) :
					new Element( "span" ).update( new Element( "span", { class:"name" }).update( vars.descr ));
	
	Object.extend( field = new Element( "input", { class: "textfield", type: "field", value: vars.values[ init.lang ]}), win.asset.textfield );
	obj.insert( field );
	field.vars = vars;
	
	field.observe( "focus", controls.bubble ).objtype = "text";

	return obj;
}
*/

